<template>
	<view class="">
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="content">群发记录</block>
			<view slot="right" @click="del()">
				删除记录
			</view>
		</cu-custom>
		<view class="">
			<uni-search-bar v-model="page.search" @confirm="search" @input="input"></uni-search-bar>
			<uni-pagination title="标题文字" show-icon="true" :total="page.total" :current="page.current"
				@change="changePage"></uni-pagination>
		</view>
		<!-- <view @click="tableToExcel">导出</view> -->
		<wyb-table ref="table" :headers="headers" :contents="contents" first-line-fixed height="700px" />
	</view>
</template>

<script>
	
	import wybTable from '@/components/wyb-table/wyb-table.vue'
	import {
		formatNumber,
		formatDateThis,
		getUnixTime
	} from "@/common/util/dateUtil.js"
	export default {
		components: {
			wybTable
		},
		data() {
			return {
				page: {
					total: 10,
					current: 1,
					size: 10,
					search: "",
				},
				headers: [
					// 	{
					// 	label: '姓名',
					// 	key: 'name'
					// }, {
					// 	label: '年龄',
					// 	key: 'age'
					// } ,
				],
				contents: []
			}
		},
		onLoad() {
			this.getDB()
		},
		methods: {
			changePage(e) {
				console.log(e)
				this.page.current = e.current;
				this.getDB()
			},
			getDB() {
				let that = this;
				this.$http.get(`/logData?search=${JSON.stringify(this.page)}`).then((e) => {
					console.log(e)
					if (e.statusCode == 200 && e.data.list.length > 0) {
						that.contents = e.data.list.map((e) => {
							return e.log
						})
						that.headers = Object.keys(that.contents[0]).map(e => {
							return {
								label: e,
								key: e
							}
						})
						that.page.total = e.data.total;
						that.page.current = e.data.current;
						that.page.size = e.data.size;
					}
				})
			},
			del() {
				let that = this;
				uni.showModal({
					title: '删除',
					content: '是否删除所以记录',
					success: function(res) {
						if (res.confirm) {
							that.$http.delete(`/logData`).then((e) => {
								console.log(e)
								if (e.data.msg == 200) {
									uni.showToast({
										title: '删除成功',
										duration: 1000
									});
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			search(e) {
				console.log(e);
				this.page.search = e.value;
				this.getDB()
			},
			input(e) {
				console.log(e)
				this.page.search = e.value;
				this.getDB()
			},
			
		}
	}
</script>

<style>
</style>
